package com.wontube.smr.conf;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.wontube.client.extension.utils.FileUtils;

/**
 * smr 项目相关的配置信息
 * @author tanggf(2012-8-2)
 *
 */
public class SmrConfig {
	private final static Logger logger = LoggerFactory.getLogger(SmrConfig.class);
	
	/** 网站图片抓取后保存的路径 */
	private String sitesImagePath;
	private String version;
	/** geo ip data path */
	private String geoIPDataPath;
	
	public static final SmrConfig SINGLE = new SmrConfig();
	
	public void load(File file){
		logger.info("begin to load smr config file !");
		String json = "";
		try {
			json = FileUtils.readAllText(file);
		} catch (Exception e) {
			logger.error("error happen when read smr config file", e);
		}
		
		if("".equals(json)){
			logger.warn("failed to load smr config file !");
		}
		
		Gson gson = new Gson();
		SmrConfig config = gson.fromJson(json, SmrConfig.class);
		this.sitesImagePath = config.sitesImagePath;
		this.version = config.version;
		this.geoIPDataPath = config.geoIPDataPath;
		
		logger.info("success to load smr config file !");
	}
	
	public String getSitesImagePath() {
		return sitesImagePath;
	}	
	public String getVersion() {
		return version;
	}
	public String getGeoIPDataPath() {
		return geoIPDataPath;
	}		
}
